/**
 * 聊天气泡
 */
class ChatContentText extends ComponentEx {

    img_arrow: eui.Image;

    lab_description: eui.Label;

    constructor() {
        super();

        this.skinName = "ChatContentTextSkin";
    }

    childrenCreated() {
        super.childrenCreated();

        this.img_arrow.anchorOffsetX = this.img_arrow.width / 2;
    }

    update(data: any, x: number, y: number) {

        GameSound.play("chat_" + data.sex + "_" + data.id);

        this.lab_description.text = ChatPanel.chatText[+data.id];

        this.show();

        let duration: number = Math.floor(acelab.width / 3);

        if (x <= duration) {//左侧
            this.img_arrow.x = 30;
        }
        else if (x >= duration * 2) {//右侧
            this.img_arrow.x = this.width - 30;
        }
        else {//中间
            this.img_arrow.x = this.width / 2;
        }

        console.log(y, this.height);

        this.x = x - this.img_arrow.x;
        this.y = y - this.height;
        this.y = this.y < 0 ? 0 : this.y;

        egret.setTimeout(this.hide, this, 3000);
    }

    show() {
        super.show();

        gameManager.layerManager.topLayer.addChild(this);
    }

    hide() {
        super.hide();

        gameManager.layerManager.topLayer.removeChild(this);
    }
}